package com.aaa.cars.controller;

import com.aaa.cars.entity.Car;
import com.aaa.cars.service.CarService;
import com.aaa.common.constants.ReturnStatus;
import com.aaa.common.util.Result;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * (Car)表控制层
 *
 * @author makejava
 * @since 2020-12-04 15:54:28
 */
@RestController
@RequestMapping("car")
public class CarController {
    /**
     * 服务对象
     */
    @Resource
    private CarService carService;

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("selectOne")
    @ApiOperation("通过主键查询单条数据")
    public Car selectOne(Integer id) {
        return this.carService.queryById(id);
    }
    /**
     * 通过主键查询单条数据
     *
     * @param vin 主键
     * @return 单条数据
     */
    @GetMapping("queryvin")
    @ApiOperation("车牌号唯一性校验")
    public Integer queryvin(String vin,Integer id) {
        return this.carService.queryvin(vin,id);
    }

    /**
     * 查询所有分页加条件查询
     *
     * @param pageNo   第几页
     * @param pageSize 每页显示数量
     * @param car      实体
     * @return Result
     */
    @PostMapping("queryAll")
    @ApiOperation("查询所有分页加条件查询")
    public Result queryAll(@RequestParam("pageNo") Integer pageNo, @RequestParam("pageSize") Integer pageSize, @RequestBody Car car) {
        System.out.println(car.getType()+","+car.getShopId()+","+car.getState()+"状态.....");
        return this.carService.queryAll(pageNo, pageSize, car);
    }


    /**
     * 更新
     *
     * @param @param car 实例对象
     * @return Result
     */
    @PostMapping("update")
    @ApiOperation("更新")
    public Result update(@ApiParam("更新json数据") @RequestBody Car car) {
        return new Result(ReturnStatus.SUCCESS.getReturnCode(),
                ReturnStatus.SUCCESS.getReturnMsg(), this.carService.update(car));
    }

    /**
     * 添加
     *
     * @param @param car 实例对象
     * @return Result
     */
    @PostMapping("insert")
    @ApiOperation("添加")
    public Result insert(@ApiParam("添加json数据") @RequestBody Car car) {
        return new Result(ReturnStatus.SUCCESS.getReturnCode(),
                ReturnStatus.SUCCESS.getReturnMsg(), this.carService.insert(car));
    }

    /**
     * 添加维修记录
     * @param car
     * @return
     */
    @PostMapping("maintain")
    @ApiOperation("添加维修记录")
    public Result maintain(@ApiParam("添加json数据") @RequestBody Car car) {
        return carService.maintain(car);
    }

    /**
     * 添加保险记录
     * @param car
     * @return
     */
    @PostMapping("carInsurance")
    public Result carInsurance(@ApiParam("添加json数据") @RequestBody Car car) {
        return carService.carInsurance(car);
    }

    /**
     * 取保
     * @return
     */
    @PostMapping("deleteInsurance")
    public Result deleteInsurance(@ApiParam("添加json数据") @RequestBody Car car) {
        return carService.deleteInsurance(car);
    }

    /**
     * 查询所有分页能租出的车
     * @param pageNo
     * @param pageSize
     * @param car
     * @return
     */
    @PostMapping("queryAllCar")
    @ApiOperation("查询所有分页能租出的车")
    public Result queryAllCar(@RequestParam("pageNo") Integer pageNo, @RequestParam("pageSize") Integer pageSize, @RequestBody Car car) {
        return carService.queryAllCar(pageNo , pageSize , car);
    }
}